// pages/orderPage/orderPage.js
var util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    wrong: "视频监控-视频无图像",
    address: "",
    userNum: "",
    name: "",
    phone: "",
    companyNum: "",
    companyName: "",
    companyPhone: "",
    latitude: "",
    longitude: "",
    price: 200,
    serviceCateId: 0,
    des: "",
    num: 1,
    singlePrice: 0.01,
    totalPrice: 0.01,
    serviceFee: 0.01,
    sendTime: "",
    problemList: [],
    problemNum: [],
    extraFee: 0,
    firstPrice: 0,
    inputPrice: 0,
    orderData: [],
    newData: [],
    clientType: "",
    parentList: [],
    changeDetail: false,
    check: false,
    sceneImg: [],
    dataList: "",
    serviceCateList: "",
    change: "",
    publishId: "",
    previewPrice: ""
  },
  addSelect: function() {
    wx.request({
      url: 'https://www.xiaozheng8.com/sendUserAddr/findAll',
      data: {
        userId: wx.getStorageSync("userId")
      },
      method: 'post',

      success: function(res) {
        util.showLoading("加载中");
        console.log(res);
        wx.navigateTo({
          url: '../addressAdministration/addressAdministration',
        })
        util.hideLoading();
      }
    })

  },
  fillAddress: function() {
    if ((wx.getStorageSync("mes") == "" || wx.getStorageSync("mes") == null || wx.getStorageSync("mes") == undefined) && (this.data.name != '' || this.data.phone != '' || this.companyName != '' || this.data.companyPhone != '')) {
      wx.navigateTo({
        url: '../fillAddress/fillAddress?name=' + this.data.name + "&phone=" + this.data.phone + "&companyName=" + this.data.companyName + "&companyPhone=" + this.data.companyPhone,
      })
    } else {
      wx.navigateTo({
        url: '../fillAddress/fillAddress',
      })
    }

  },
  problem: function() {
    wx.navigateTo({
      url: '../problem/problem',
    })
  },
  price: function(e) {
    this.setData({
      price: e.detail.value
    })

  },
  // 点击用户协议
  check: function() {
    this.setData({
      check: !this.data.check
    })
  },
  protocol: function(e) {
    var protocol = e.currentTarget.dataset.protocol;
    wx.navigateTo({
      url: '../protocol/protocol?protocol=' + protocol,
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  // 对项目列表进行排列
  request: function() {
    var that = this;
    wx.request({
      url: 'https://www.xiaozheng8.com/service/cate/findAll',
      // url: 'http://192.168.43.244:8002/service/cate/findAll',
      method: 'post',
      data: "",
      success: function(res) {
        var orderData = wx.getStorageSync("orderDataList");
        // console.log(orderData.length);
        if (orderData == "" || orderData == undefined) {

        } else {


          for (var i = 0; i < orderData.length; i++) {
            console.log(orderData[i].titleContent)
            if (orderData[i].titleContent.length == 0) {
              orderData.splice(i, 1)
            }
            wx.setStorageSync("orderDataList", orderData)
          }
          that.setData({
            orderData: wx.getStorageSync("orderDataList"),
            newData: res.data.data
          })
          var a = [];
          var b = [];

          for (var i = 0; i < that.data.orderData.length; i++) {


            // 按标题分类
            for (var j = 0; j < that.data.orderData.length; j++) {
              if (that.data.orderData[i].title == undefined || that.data.orderData[j].title == undefined) {

              } else {
                if (i != j && that.data.orderData[i].title == that.data.orderData[j].title) {
                  // 如果标题相同，放在同一标题下
                  console.log(that.data.orderData[j].titleContent[0]);
                  var inTitle = [];
                  inTitle.push(that.data.orderData[j].titleContent[0]);
                  console.log(inTitle);
                  that.data.orderData[i].titleContent.push(inTitle[0]);
                  console.log(that.data.orderData[i].titleContent);
                  that.setData({
                    orderData: that.data.orderData
                  })
                  console.log(that.data.orderData);


                }
              }
            }

          }
          console.log(that.data.orderData);
          // 相同标题的放在同一目录下
          that.deleteRepet();
          console.log(that.data.orderData);
          that.deleteRepet();

          // 计算价格
          that.price();
        }
      },
      fail: function(res) {},
      complete: function(res) {},
    })
    // // 对数据进行赋值
    if (wx.getStorageSync("name") != "" || wx.getStorageSync("name") != undefined) {
      this.setData({
        name: wx.getStorageSync("name"),
        phone: wx.getStorageSync("phone"),
        companyName: wx.getStorageSync("company"),
        companyPhone: wx.getStorageSync("companyPhone"),
      });
    }

    console.log(wx.getStorageSync("location") != "");
    if ((wx.getStorageSync("mes") == "" || wx.getStorageSync("mes") == undefined || wx.getStorageSync("mes") == null) && wx.getStorageSync("location") != "") {
      var address = wx.getStorageSync("location").address + "(" + wx.getStorageSync("location").name + ")";
      that.setData({
        address: address,
        latitude: wx.getStorageSync("location").latitude,
        longitude: wx.getStorageSync("location").longitude,
      })
      console.log(address);

    } else if (wx.getStorageSync("mes") != "" && wx.getStorageSync("mes") != undefined && wx.getStorageSync("mes") != null) {
      var mes = wx.getStorageSync("mes");
      that.setData({
        // wrong: wrong + "-" + sonWrong,
        address: mes.addr,
        latitude: wx.getStorageSync("mes").lat,
        longitude: wx.getStorageSync("mes").lng,
      });
      console.log(that.data.latitude);
    } else {

    }
  },
  // 去重
  deleteRepet: function() {
    var that = this
    for (var i = 0; i < that.data.orderData.length; i++) {

      for (var j = 0; j < that.data.orderData.length; j++) {
        if (i + 1 > that.data.orderData.length) {
          continue;
        } else {
          if (i != j && that.data.orderData[i].title == that.data.orderData[j].title) {
            that.data.orderData.splice(i, 1);
          }
          that.setData({
            orderData: that.data.orderData,

          })
        }
      }
      console.log(that.data.orderData);
      that.setData({
        projectMes: that.data.orderData
      })
    }
  },
  // 计算价格
  price: function() {
    var that = this;
    if (wx.getStorageSync("factor") == null || wx.getStorageSync("factor") == undefined) {
      that.setData({
        factor: 1
      })
    } else {
      that.setData({
        factor: wx.getStorageSync("factor")
      })
    }
    var price = 0;
    var originalPrice = 0;
    for (var i = 0; i < that.data.orderData.length; i++) {
      for (var j = 0; j < that.data.orderData[i].titleContent.length; j++) {
        that.data.orderData[i].titleContent[j].price = Math.round(that.data.orderData[i].titleContent[j].originalPrice * that.data.factor);
        that.setData({
          orderData: that.data.orderData
        });
        if (that.data.orderData[i].titleContent[j].originalPrice == undefined) {

        } else {
          price = that.data.orderData[i].titleContent[j].originalPrice + price
        }

      }
    }
    console.log(price);
    if (Math.round(price * that.data.factor) > 200) {
      that.setData({
        price: Math.round(price * that.data.factor),
        projectMes: that.data.orderData,
        previewPrice: Math.round(price * that.data.factor)
      })
    } else {
      that.setData({
        price: 200,
        projectMes: that.data.orderData,
        previewPrice: 200
      })
    }

  },
  // 选择客户类型
  select: function(e) {
    wx.navigateTo({
      url: '../select/select',
    })
  },
  // 删除项目
  deleteObj: function(e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    var title = e.currentTarget.dataset.title;

    for (var i = 0; i < that.data.orderData.length; i++) {
      if (that.data.orderData[i].title == title) {
        that.data.orderData[i].titleContent.splice(index, 1);
        that.setData({
          orderData: that.data.orderData,
          projectMes: that.data.orderData
        })
        wx.setStorageSync("orderDataList", that.data.orderData)
      };

    }
    that.price();


  },
  // 新增项目
  addObj: function() {
    var that = this;
    if (that.data.clientType == "" || that.data.clientType == undefined) {
      wx.showModal({
        title: '提示',
        content: '请先选择客户类型',
      })
    } else {
      wx.navigateTo({
        url: '../chooseServer/chooserServer?index=' + that.data.setIndex,
      })
    }

  },
  // 跳转到场景图
  sceneImg() {
    wx.navigateTo({
      url: '../sceneImg/sceneImg',
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    if (wx.getStorageSync("userCheck") == "" || wx.getStorageSync("userCheck") == undefined) {

    } else {
      that.setData({
        check: true
      })
    }
    console.log(options);
    if (options.index == "" || options.index == undefined) {
      that.setData({
        setIndex: 0
      })
    } else {
      this.setData({
        setIndex: options.index
      })
    }
    // 问题描述内容
    this.setData({
      des: wx.getStorageSync("des")
    })
    if (options.change != undefined) {
      wx.setNavigationBarTitle({
        title: '修改订单',
      })
      this.setData({
        change: options.change,

      })
      var dataList = JSON.parse(unescape(options.dataList));
      console.log(dataList);
      that.setData({
        dataList: dataList,
        name: dataList.name,
        phone: dataList.phone,
        companyName: dataList.companyName,
        companyPhone: dataList.companyPhone,
        des: dataList.serviceDesc,
        publishId: dataList.publishId,
        sceneImg: dataList.img
        // changeDetail:true
      })
    } else {
      wx.setNavigationBarTitle({
        title: '立即下单',
      })

    }
    var mes = wx.getStorageSync("mes");
    if (wx.getStorageSync("location") == "") {} else {
      that.setData({
        latitude: wx.getStorageSync("location").latitude,
        longitude: wx.getStorageSync("location").longitude,
      })
    }

  },
  delete: function(e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    this.data.problemList.splice(index, 1);
    this.setData({
      problemList: that.data.problemList
    });
  },
  // 修改项目
  changeObj: function(e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    // 第一位
    var index = e.currentTarget.dataset.index;
    // 第二位
    var site = e.currentTarget.dataset.site;

    var third = e.currentTarget.dataset.third;
    var titleIndex = e.currentTarget.dataset.titleindex;
    var cateId = e.currentTarget.dataset.cateid;
    this.setData({
      titleIndex: titleIndex,
      splice: site
    })
    console.log(titleIndex);
    console.log("-----------------------")
    console.log(that.data.orderData);
    wx.setStorageSync("orderData", that.data.orderData)
    // console.log(id);
    // console.log(index);
    wx.navigateTo({
      url: '../chooseDetail/chooseDetail?id=' + id + "&index=" + index + "&site=" + third + "&back=" + 1 + "&splice=" + site + "&cateId=" + cateId,
      success: function() {

      }
    });




  },
  title: function(e) {
    var first = e.currentTarget.dataset.first;
    var second = e.currentTarget.dataset.second;
    wx.navigateTo({
      url: '../chooseContent/chooseContent?index=' + second + "&id=" + first + "&title=" + 1,
    })
  },
  orderData: function() {
    var that = this;
    for (var i = 0; i < that.data.orderData.length; i++) {
      if (that.data.orderData[i].title == that.data.titleIndex) {
        that.data.orderData[i].titleContent.splice(that.data.splice, 1)
        that.setData({
          orderData: that.data.orderData,
          projectMes: that.data.orderData
        })
      }
    }
  },
  // 可手动输入价格，能输入非数字算我输
  fee(e) {
    var price = this.validateNumber(e.detail.value);
    this.setData({
      price: price
    })
    // if(price<200){
    //   this.setData({
    //     price:200
    //   })
    // }
  },
  blur() {
    if (this.data.previewPrice * 0.8 > this.data.price) {
      wx.showToast({
        title: '不能设置比初始价格的80%更小',
        icon: "none"
      })
      this.setData({
        price: previewPrice
      })
    } else if (this.data.price < 200 || this.data.price == "") {
      this.setData({
        price: 200
      })
    }
  },
  validateNumber(val) {
    return val.replace(/\D/g, '')
  },
  minFee: function(e) {
    // 如果价格小于200，自动变成200
    var that = this;
    if (this.data.price < 200) {
      that.setData({
        price: 200
      });
      wx.showToast({
        title: '设置最低价为200',
        icon: "none"
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },
  // 服务描述
  des: function(e) {
    this.setData({
      des: e.detail.value
    })
    wx.setStorageSync("des", this.data.des);
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this;
    console.log(this.data.changeDetail);
    console.log(wx.getStorageSync("orderData"))
    console.log(wx.getStorageSync("orderDataList"))
    if (this.data.changeDetail == true) {
      that.setData({
        orderData: wx.getStorageSync("orderData"),
        projectMes: wx.getStorageSync("orderData")
      });
      console.log(that.data.projectMes);
      that.setData({
        changeDetail: false
      })
      that.price();

      wx.setStorageSync("orderDataList", that.data.orderData)
      wx.setStorageSync("orderData", that.data.orderData)
    } else {
      // 订单进行修改
      // 如果是已下的订单，进入此页面时，本地储存的服务项目为null，即用此做判断
      console.log(that.data.dataList);
      if ((wx.getStorageSync("orderDataList") == null || wx.getStorageSync("orderDataList") == "" || wx.getStorageSync("orderData") == "") && that.data.dataList != "") {
        console.log(that.data.dataList);

        //上传的project没有所在位置信息
        // 添加所在位置信息？
        // delete that.data.orderData[i].titleContent[j].first;
        // delete that.data.orderData[i].titleContent[j].second;
        // delete that.data.orderData[i].titleContent[j].third;
        // delete that.data.orderData[i].titleContent[j].originalPrice;
        // 异步请求没办法,用最脑残的方式
        // 获取项目列表

        wx.request({
          url: 'https://www.xiaozheng8.com/service/cate/findAll',
          method: 'post',
          data: "",
          success: function(res) {
            console.log(res);
            that.setData({
              serviceCateList: res.data.data
            })

            var project = that.data.dataList.project;
            console.log(that.data.serviceCateList);
            console.log(that.data.dataList.project);
            for (var i = 0; i < that.data.dataList.project.length; i++) {
              for (var j = 0; j < that.data.serviceCateList.sonList.length; j++) {
                for (var k = 0; k < that.data.serviceCateList.sonList[j].sonList.length; k++) {

                  for (var l = 0; l < that.data.serviceCateList.sonList[j].sonList[k].sonList.length; l++) {
                    // console.log(that.data.serviceCateList.sonList[j].sonList[k].sonList[l]);
                    for (var n = 0; n < that.data.dataList.project[i].titleContent.length; n++) {
                      console.log(that.data.dataList.project[i].titleContent[n].cateId)
                      console.log(that.data.serviceCateList.sonList[j].sonList[k].sonList[l].cateId)
                      if (that.data.dataList.project[i].titleContent[n].cateId == that.data.serviceCateList.sonList[j].sonList[k].sonList[l].cateId) {
                        console.log(that.data.serviceCateList.sonList[j].sonList[k].sonList[l])
                        var price = 0;
                        for (var p = 0; p < that.data.serviceCateList.sonList[j].sonList[k].sonList[l].prop2List.length; p++) {
                          price = price + that.data.serviceCateList.sonList[j].sonList[k].sonList[l].prop2List[p].prop2s[0].fee
                        }
                        console.log(price);
                        project[i].titleContent[n].first = j;
                        project[i].titleContent[n].second = k;
                        project[i].titleContent[n].third = l;
                        project[i].titleContent[n].originalPrice = price;
                        console.log(j)
                        console.log(k)
                        console.log(l)
                        // project[i].first = j;
                        // project.second = k;
                        // project.third = l;
                        console.log(project)
                        that.setData({
                          projectMes: project,
                          price: that.data.dataList.totalFee,
                          address: that.data.dataList.serviceAddr,
                          latitude: that.data.dataList.lat,
                          longitude: that.data.dataList.lng
                        })
                        console.log(that.data.address);
                        wx.setStorageSync("orderDataList", that.data.projectMes)
                        that.setData({
                          orderData: that.data.projectMes
                        })
                        wx.setStorageSync("orderData", that.data.projectMes)
                        // 
                      }
                    }

                  }
                }
              }

            }
          }
        })
        console.log(that.data.serviceCateList);


      } else {
        // 对服务项目进行整理并对数据进行
        that.request();
      }



    }
    // console.log(this.data.clientType)
    // 获取之前选择的客户类型
    this.setData({
      clientType: wx.getStorageSync("client")
    })
    console.log(this.data.sceneImg);

  },
  // 图片预览
  preview(e) {
    var that = this;
    var index = e.currentTarget.dataset.index
    wx.previewImage({
      current: that.data.sceneImg[index],
      urls: that.data.sceneImg,

    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  addCount: function(e) {

    console.log(this);
    var price = this.data.price;

    price = price + 100
    this.setData({
      price: price,
    })
  },
  minusCount: function(e) {
    var price = this.data.price;
    var that = this;
    if (price - 100 >= 200) {
      price = price - 100;
    } else {
      price = 200;
      wx.showToast({
        title: '最低额为200',
        icon: "none"
      })
    }
    that.setData({
      price: price,

    })
  },
  // 修改数据
  alter() {
    var that = this;
    if (that.data.clientType == "" || that.data.clientType == undefined) {
      wx.showModal({
        title: '提示',
        content: '请填写客户类型',
        showCancel: false,

      })
    } else if (that.data.orderData.length == 0 || (that.data.orderData.length != 0 && that.data.orderData[0].titleContent.length == 0)) {
      wx.showModal({
        title: '提示',
        content: '请填写项目信息',
        showCancel: false,

      })
    } else if (this.data.address == "" || this.data.address == "undefined(undefined)" || this.data.address == null) {
      wx.showModal({
        title: '提示',
        content: '请填写服务地点',
        showCancel: false,

      })
    } else if (this.data.des == "" || this.data.des == undefined || this.data.des == null) {
      wx.showModal({
        title: '提示',
        content: '请输入问题描述',
        showCancel: false,

      })
      console.log("11")
    } else if (this.data.name == "" || this.data.name == undefined || this.data.name == null) {
      wx.showModal({
        title: '提示',
        content: '请填写客户信息',
        showCancel: false,

      })
      // } else if (that.data.check == false) {

      //   // wx.showToast({
      //   //   title: '请先同意用户协议及隐私声明',
      //   //   duration: 3000,
      //   //   icon: "none"
      //   // })
      //   wx.showModal({
      //     title: '提示',
      //     content: '请先同意用户协议及隐私声明',
      //     // showCancel:false,
      //     success: function (res) {
      //       if (res.confirm) {
      //         wx.navigateTo({
      //           url: '../protocol/protocol?protocol=' + 1,
      //         })
      //       }
      //     }
      //   })
    } else {
      wx.showModal({
        title: '提示',
        content: '是否确认修改订单',
        confirmText: "确定",
        cancelText: "取消",
        success: function(res) {
          if (res.confirm) {
            wx.showToast({
              title: "提交中",
              icon: 'loading',
              mask: true,
              duration: 2000
            });
            if (that.data.problemList == "" || that.data.problemList == null || that.data.problemList == undefined) {

            } else {
              for (var i = 0; i < that.data.problemList.length; i++) {
                that.data.problemNum.push(that.data.problemList[i].id)
                console.log(that.data.problemList);
              }
              that.setData({
                problemNum: that.data.problemNum
              });
            }
            for (var i = 0; i < that.data.orderData.length; i++) {
              console.log(that.data.orderData[i].titleContent);
              for (var j = 0; j < that.data.orderData[i].titleContent.length; j++) {
                delete that.data.orderData[i].titleContent[j].first;
                delete that.data.orderData[i].titleContent[j].second;
                delete that.data.orderData[i].titleContent[j].third;
                delete that.data.orderData[i].titleContent[j].originalPrice;
              }
              console.log(that.data.orderData);
              that.setData({
                orderData: that.data.orderData
              })
            }
            console.log(that.data.orderData);
            console.log(that.data.publishId)
            wx.request({
              url: 'https://www.xiaozheng8.com/serviceOrder/update?publishId=' + that.data.publishId,
              method: "post",
              data: {
                publishId: that.data.publishId,
                userId: wx.getStorageSync("userId"),
                serviceAddr: that.data.address,
                name: that.data.name,
                phone: that.data.phone,
                companyName: that.data.companyName,
                companyPhone: that.data.companyPhone,
                lat: that.data.latitude,
                lng: that.data.longitude,
                cateId: 9,
                serviceDesc: that.data.des,
                serviceFee: that.data.firstPrice,
                totalFee: that.data.price,
                project: that.data.orderData,
                factorId: wx.getStorageSync("factorId"),
                imgs: that.data.sceneImg
              },
              success: function(res) {
                console.log(res)
                // wx.setStorageSync("orderId", res.data.data.publishId)
                // wx.setStorageSync("status", res.data.data.status)
                wx.setStorageSync("userCheck", true)
                wx.setStorageSync("problemList", null)
                wx.setStorageSync("problem", null)
                wx.setStorageSync("des", null);
                wx.setStorageSync("orderDataList", null)
                wx.setStorageSync("factor", null)
                wx.setStorageSync("client", "")
                wx.setStorageSync("orderData", null)

                wx.reLaunch({
                  url: '../userOrder/userOrder',
                })
              },
              fail(res) {
                wx.navigateBack({
                  delta: 1,
                })
                wx.showModal({
                  title: '提示',
                  content: '修改失败',
                  showCancel: false
                })
              }
            });
          }
        }
      })
    }

  },
  // 提交数据
  post: function() {
    var that = this;
    if (that.data.clientType == "" || that.data.clientType == undefined) {
      wx.showModal({
        title: '提示',
        content: '请填写客户类型',
        showCancel: false,

      })
    } else if (that.data.orderData.length == 0 || (that.data.orderData.length != 0 && that.data.orderData[0].titleContent.length == 0)) {
      wx.showModal({
        title: '提示',
        content: '请填写项目信息',
        showCancel: false,

      })
    } else if (this.data.address == "" || this.data.address == "undefined(undefined)" || this.data.address == null) {
      wx.showModal({
        title: '提示',
        content: '请填写服务地点',
        showCancel: false,

      })
    } else if (this.data.des == "" || this.data.des == undefined || this.data.des == null) {
      wx.showModal({
        title: '提示',
        content: '请输入问题描述',
        showCancel: false,

      })
      console.log("11")
    } else if (this.data.name == "" || this.data.name == undefined || this.data.name == null) {
      wx.showModal({
        title: '提示',
        content: '请填写客户信息',
        showCancel: false,

      })
    } else if (that.data.check == false) {

      // wx.showToast({
      //   title: '请先同意用户协议及隐私声明',
      //   duration: 3000,
      //   icon: "none"
      // })
      wx.showModal({
        title: '提示',
        content: '请先同意用户协议及隐私声明',
        // showCancel:false,
        success: function(res) {
          if (res.confirm) {
            wx.navigateTo({
              url: '../protocol/protocol?protocol=' + 1,
            })
          }
        }
      })
    } else {
      wx.showModal({
        title: '提示',
        content: '是否确认提交订单',
        confirmText: "确定",
        cancelText: "取消",
        success: function(res) {
          if (res.confirm) {
            wx.showToast({
              title: "提交中",
              icon: 'loading',
              mask: true,
              duration: 2000
            });
            if (that.data.problemList == "" || that.data.problemList == null || that.data.problemList == undefined) {

            } else {
              for (var i = 0; i < that.data.problemList.length; i++) {
                that.data.problemNum.push(that.data.problemList[i].id)
                console.log(that.data.problemList);
              }
              that.setData({
                problemNum: that.data.problemNum
              });
            }
            for (var i = 0; i < that.data.orderData.length; i++) {
              for (var j = 0; j < that.data.orderData[i].titleContent.length; j++) {
                delete that.data.orderData[i].titleContent[j].first;
                delete that.data.orderData[i].titleContent[j].second;
                delete that.data.orderData[i].titleContent[j].third;
                delete that.data.orderData[i].titleContent[j].originalPrice;
              }
              console.log(that.data.orderData);
              that.setData({
                orderData: that.data.orderData
              })
            }
            console.log(that.data.orderData);
            wx.request({
              url: 'https://www.xiaozheng8.com/serviceOrder/add/v2',
              method: "post",
              data: {
                userId: wx.getStorageSync("userId"),
                serviceAddr: that.data.address,
                name: that.data.name,
                phone: that.data.phone,
                companyName: that.data.companyName,
                companyPhone: that.data.companyPhone,
                lat: that.data.latitude,
                lng: that.data.longitude,
                cateId: 9,
                serviceDesc: that.data.des,
                serviceFee: that.data.firstPrice,
                totalFee: that.data.price,
                project: that.data.orderData,
                factorId: wx.getStorageSync("factorId"),
                imgs: that.data.sceneImg
              },
              success: function(res) {
                console.log(res)
                wx.setStorageSync("orderId", res.data.data.publishId)
                wx.setStorageSync("status", res.data.data.status)
                wx.setStorageSync("userCheck", true)
                wx.setStorageSync("problemList", null)
                wx.setStorageSync("problem", null)
                wx.setStorageSync("des", null);
                wx.setStorageSync("orderDataList", null)
                wx.setStorageSync("factor", null)
                wx.setStorageSync("client", "")
                wx.setStorageSync("orderData", null)

                wx.reLaunch({
                  url: '../successPage/successPage',
                });
              },
              fail(res) {
                wx.reLaunch({
                  url: '../order/order',
                })
                wx.showModal({
                  title: '提示',
                  content: '下单失败',
                  showCancel: false
                })
              }
            });


          } else {

          }
        }
      })



    }

  }



})